<?php
/*********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
*
 ********************************************************************************/
$onlymine=$_REQUEST['onlymine'];
if($onlymine == 'true') {
    $mine_selected = ' selected="selected"';
    $all_selected = '';
} else {
    $mine_selected = '';
    $all_selected = ' selected="selected"';
}

?>
	<div class="left">
   	<span class="lvtHeaderText"><?php echo getTranslatedString('SHOW');?></span>
   	<select id="ticket_status_combo" onchange="this.form.module.value='HelpDesk';this.form.action.value='index';this.form.fun.value='home'; showTickets(index)">
   		<?php 
   			echo getStatusComboList($show);
   		?>
   	</select>
   	<?php $show = $client->call('show_all',array('module'=>'HelpDesk'), $Server_Path, $Server_Path);
   	if($show == 'true'){
   		echo '<select id="only_mine_combo" name="list_type" onchange="getList(this, \'HelpDesk\');">
   				<option value="mine"' . $mine_selected . '>' . getTranslatedString('MINE') . '</option>
   				<option value="all"' . $all_selected . '>' .getTranslatedString('ALL') . '</option>
   				</select>';
   		} 
   	?>
	</div>
	<div class="right">
      <input class="crmbutton small cancel" name="newticket" type="submit" value="<?php echo getTranslatedString('LBL_NEW_TICKET');?>" onclick="this.form.module.value='HelpDesk';this.form.action.value='index';this.form.fun.value='newticket'" />
    	<input class="crmbutton small cancel" name="srch" type="button" value="<?php echo getTranslatedString('LBL_SEARCH');?>" onclick="showSearchFormNow('tabSrch');" />
 	</div>
</form>
</div><!-- End action -->

<?php
global $result;
$closedlist = '';

if($result == '') {
	$list .= '<div class="pageTitle">' . getTranslatedString('LBL_NONE_SUBMITTED') . '</div>' . "\n";
} else {

	$header = $result[0]['head'][0];
	$nooffields = count($header);
	$data = $result[1]['data'];
	$rowcount = count($data);
	$showstatus = $_REQUEST['showstatus'];
		if($showstatus != '' && $rowcount >= 1) {
			$list .= '<div class="mnu">' . getTranslatedString($showstatus) . ' ' . getTranslatedString('LBL_TICKETS') . ' </div>' . "\n";
			$list .= '<table class="list">' . "\n";
			$list .= '<tr>' . "\n";
	
			for($i=0; $i<$nooffields; $i++)
			{
				$header_value = $header[$i]['fielddata'];
				$list .= '<th class="detailedViewHeader">' . $header_value . '</th>' . "\n";
			}
			$list .= '</tr>' . "\n";
	
			$ticketexist = 0;
			for($i=0;$i<count($data);$i++)
			{		
				$ticketlist = '';
		
				if ($i%2==0)
					$ticketlist .= '<tr class="dvtLabel">' . "\n";
				else
					$ticketlist .= '<tr class="dvtInfo">' . "\n";
			
				$ticket_status = '';
				for($j=0; $j<$nooffields; $j++) {			
					$ticketlist .= '<td>' . getTranslatedString($data[$i][$j]['fielddata']) . '</td>' . "\n";
					if ($header[$j]['fielddata'] == 'Status') {
						$ticket_status = $data[$i][$j]['fielddata'];
					}
				}
			$ticketlist .= '</tr>' . "\n";
	
			if($ticket_status == $showstatus){
				$list .= $ticketlist; 
				$ticketexist++;
			}		
		}
		if($ticketexist == 0)
		{
			$list .= '<div class="pageTitle">' . getTranslatedString('LBL_NONE_SUBMITTED') . '</div>' . "\n";
		}
	
		$list .= '</table>' . "\n";
	
	}
	else {
		$list .= '<div class="mnu">' . getTranslatedString('LBL_MY_OPEN_TICKETS') . '</div>' . "\n";
		$list .= '<table class="list">' . "\n";
		$list .= '<tr>' . "\n";
			
		$closedlist .= '<div class="mnu">' . getTranslatedString('LBL_CLOSED_TICKETS') . '</div>' . "\n";
		$closedlist .= '<table class="list">' . "\n";
		$closedlist .= '<tr>' . "\n";
		
		for($i=0; $i<$nooffields; $i++)
		{
			$header_value = $header[$i]['fielddata'];
			$headerlist .= '<th class="detailedViewHeader">' . getTranslatedString($header_value) . '</th>' . "\n";
		}
		$headerlist .= '</tr>' . "\n";
		
		$list .= $headerlist;
		$closedlist .= $headerlist;
	
		for($i=0;$i<count($data);$i++)
		{
			$ticketlist = '';
			
			if ($i%2==0)
				$ticketlist .= '<tr class="dvtLabel">' . "\n";
			else
				$ticketlist .= '<tr class="dvtInfo">' . "\n";
			
			$ticket_status = '';
			for($j=0; $j<$nooffields; $j++) {		
				$ticketlist .= '<td>'.$data[$i][$j]['fielddata'].'</td>' . "\n";
				if ($header[$j]['fielddata'] == 'Status') {
					$ticket_status = $data[$i][$j]['fielddata'];
				}
			}
			$ticketlist .= '</tr>' . "\n";
	
			if($ticket_status == getTranslatedString('LBL_STATUS_CLOSED'))
				$closedlist .= $ticketlist;
			elseif($ticket_status != '')
				$list .= $ticketlist;
		}	
	
		$list .= '</table>' . "\n";
		$closedlist .= '</table>' . "\n";
	
		$list .= $closedlist . "\n";
	}
}
echo $list;

?>